package com.back.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.util.comm.RequestUtil;

public class LoginFilter implements Filter {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest re = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;
		String url =re.getRequestURI();
		if(url.indexOf("/back/login.jsp")==-1){
		Object obj = RequestUtil.getLoginUserFromSession(re, "login");
		  if (obj == null) {

			res.sendRedirect(re.getContextPath()+"/back/login.jsp");
			return;
			} 
		}
			chain.doFilter(request, response);
		

	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
